#ifndef CONNECTION_H
#define CONNECTION_H

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDateTime>
#include <QString>
#include <QVariant>

static const QString data_base_name("database.db");

static QString getDay()
{
    QString day;
    QDateTime current_date_time = QDateTime::currentDateTime();
    day = current_date_time.toString("yyyy-MM-dd");

    return day;
}

static QString getMonth()
{
    QString month;
    QDateTime current_date_time = QDateTime::currentDateTime();
    month = current_date_time.toString("yyyy-MM");

    return month;
}

static bool createConnection()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(data_base_name);

    if(!db.open()) return false;

    bool result = false;
    QSqlQuery query;
    result = query.exec(QString(
                            "create table if not exists reward (name varchar not null primary key, record int not null default 1)"));

    result = query.exec(QString(
                            "create table if not exists punishment (name varchar not null primary key, record int not null default 1)"));

//    QString month = getMonth();
//    QString sql(QString("create table if not exists '%1' ("
//                        "day int not null primary key,"
//                        "name varchar,"
//                        "complete int,"
//                        "time TIMESTAMP default(datetime('now', 'localtime')))"
//                        ).arg(month));

//    result = query.exec(sql);

    return result;
}

#endif // CONNECTION_H
